package com.jacklin.utils;

import com.jacklin.enums.CodeEnum;

/**
 * @Author:JackLin
 * @Create 2019/4/1 13:18
 */
public class EnumUtil {

    /**
     * 通过传入相应枚举的code来获取枚举信息
     * @param code
     * @param enumClass
     * @param <T>
     * @return
     */
    public static <T extends CodeEnum> T getByCode(Integer code, Class<T> enumClass){
        for (T each:enumClass.getEnumConstants()){
            if (code.equals(each.getCode())){
                return each;    //如果枚举的code等于传入的code，则返回这个枚举
            }
        }
        return null;
    }
}
